package com.explorati.LeetCode392.issubsequence;

/**
 * 392. Is Subsequence
 * 
 * @author explorati
 *
 */
public class Solution {
	// t是大的字符串，s是子串
	public static boolean isSubsequence(String s, String t) {
		if (s.length() == 0) {
			return true;
		}
		if(s.charAt(0) == ' '){
			return true;
		}
		int i = s.length() - 1;
		int j = t.length() - 1;

		while (i >= 0 && j >= 0) {
			if (t.charAt(j) == s.charAt(i)) {
				i--;
				j--;
				if (i == -1) {
					return true;
				}
			} else {
				j--;
			}
		}
		return false;
	}

	public static void main(String[] args) {
		String s = " ";
		String t = "ab";
		System.out.println(isSubsequence(s, t));
	}
}
